<template>
  <div class="wrapper">
    <div class="sear">
      <p>亚朵星球</p>
      <div class="nav">
        <span
          v-for="item in titleList"
          :key="item.type"
          @click="clickTab(item.type)"
          :class="item.type === indexs ? 'active' : ''"
          >{{ item.title }}</span
        >
      </div>
    </div>
    <div class="kong"></div>
    <div class="box">
      <dl
        v-for="item in detailList"
        :key="item.goodsId"
        @click="toDeatails(item.goodsId)"
      >
        <dt><img :src="item.goodsImgUrl" alt="" /></dt>
        <dd>
          <p class="title">{{ item.goodsName }}</p>
        </dd>
        <dd v-if="item.discountTag">
          <p class="time">{{ item.discountTag }}</p>
          <p class="price">
            <span
              >折后<span class="yuan">￥{{ item.goodsDiscountPrice }}</span
              >起</span
            >
            <s>￥{{ item.minGoodsPrice }}</s>
          </p>
        </dd>
        <dd v-else>
          <p class="prices">￥{{ item.minGoodsPrice }}</p>
        </dd>
      </dl>
    </div>
    <div class="lodin">加载中。。。</div>
  </div>
</template>

<script>
import { getDetailList } from "../../../server";
export default {
  data() {
    return {
      goodId: "",
      detailList: [],
      indexs: 0,
      titleList: [
        {
          title: "销量",
          type: 0,
        },
        {
          title: "价格",
          type: 1,
        },
        {
          title: "上新",
          type: 3,
        },
      ],
    };
  },
  onLoad(option) {
    if (option.id) {
      this.goodId = option.id;
    }
  },
  async onShow() {
    let res = await getDetailList({
      orderByType: 0,
      goodsName: "",
      isGroup: "1",
      groupType: "1",
      newSearch: 0,
      pageNo: 1,
      pageSize: 10,
      id: this.goodId,
    });
    console.log(res);
    if (res.retcode == 0) {
      this.detailList = res.result.frontGoodsList;
    }
  },
  methods: {
    async clickTab(type) {
      this.indexs = type;
      console.log(this.indexs);
      let res = await getDetailList({
        orderByType: type,  
        goodsName: "",
        isGroup: "1",
        groupType: "1",
        newSearch: 0,
        pageNo: 1,
        pageSize: 10,
        id: this.goodId,
      });
      console.log(res);
      if (res.retcode == 0) {
        this.detailList = res.result.frontGoodsList;
        console.log(this.detailList);
      }
    },
    toDeatails(id) {
      uni.navigateTo({
        url: `/subpacks/mall/goodsDetail/goodsDetail?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
  height: 100%;
}
.sear {
  width: 100%;
  height: 250rpx;
  background-color: #fff;
  position: fixed;
  z-index: 200;
  p {
    margin-top: 20rpx;
    margin-left: 30rpx;
    display: inline-block;
    width: 600rpx;
    height: 35%;
    border-radius: 40rpx;
    background: #eee;
    padding-left: 80rpx;
    line-height: 80rpx;
    color: #999;
    font-size: 36rpx;
  }
  .nav {
    width: 100%;
    height: 90rpx;
    border-top: 1rpx solid #eee;
    margin-top: 50rpx;
    display: flex;
    justify-content: space-around;

    span {
      text-align: center;
      line-height: 100rpx;
    }
    .active {
      border-bottom: 2px solid #333;
    }
  }
}
.kong {
  width: 100%;
  height: 250rpx;
}
.box {
  flex: 1;
  background-color: #eee;
  display: flex;
  flex-wrap: wrap;
  dl {
    width: 46%;
    margin-left: 3%;
    margin-top: 3%;
    height: 600rpx;
    background-color: #fff;

    dt {
      img {
        width: 100%;
        height: 350rpx;
      }
    }
    .title {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    dd {
      width: 96%;
      margin-left: 20rpx;
    }
    .time {
      display: inline-block;
      background-color: rgba(255, 174, 0, 0.692);
      color: rgb(255, 136, 0);
      font-size: 24rpx;
      margin-top: 30rpx;
      margin-bottom: 15rpx;
    }
    .price {
      display: flex;
      span {
        font-size: 25rpx;
        .yuan {
          font-size: 30rpx;
          font-weight: 600;
        }
      }
      s {
        padding-left: 60rpx;
        text-decoration: line-through;
        font-size: 22rpx;
        color: #999;
      }
    }
    .prices {
      font-size: 30rpx;
      font-weight: 600;
      margin-top: 60rpx;
    }
  }
}
.lodin {
  width: 100%;
  height: 100rpx;
  background-color: #eee;
  text-align: center;
  line-height: 100rpx;
}
</style>